<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML >
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>添加班级</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	
    <%@include file="/pages/head/head.jsp" %>
     
  </head>
  
  <body>
   <div id="wrapper">
        <!-- 左边菜单 -->
         <%@include file="/pages/left/leftmenu.jsp" %>

        <div id="page-wrapper" class="gray-bg dashbard-1">
             <!-- 引入top菜单 -->
              <%@include file="/pages/left/topmenu.jsp" %>
            
            <!--左边内容开发，开始  -->
              <div class="row wrapper border-bottom white-bg page-heading">
                <div class="col-lg-10">
                    <h2>班级资料</h2>
                    <ol class="breadcrumb">
                        <li>
                            <a href="index.html">主页</a>
                        </li>
                        <li>
                            <a>班级资料</a>
                        </li>
                        <li>
                            <strong>添加班级资料</strong>
                        </li>
                    </ol>
                </div>
                <div class="col-lg-2">

                </div>
            </div>
            <div class="wrapper wrapper-content animated fadeInRight">
                
                <div class="row">
                    <div class="col-lg-14">
                        <div class="ibox float-e-margins">
                            <div class="ibox-title">
                                <h5>添加班级资料</h5>
                                <div class="ibox-tools">
                                    <a class="collapse-link">
                                        <i class="fa fa-chevron-up"></i>
                                    </a>
                                </div>
                            </div>
                            <div class="ibox-content">
                                <form class="form-horizontal m-t" id="classrequire" name="classrequire" method="post" >
                                
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">班级编号：</label>
                                        <div class="col-sm-8">
                                            <input id="classCode" name="classCode"  maxlength="30"  class="form-control" type="text">
                                            <input id="classId" name="class_id"  maxlength="30"  class="form-control" type="hidden">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">班级名称：</label>
                                        <div class="col-sm-8">
                                            <input id="className" name="className" maxlength="30" class="form-control" type="text">
                                        </div>
                                    </div>
                                   
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">学年：</label>
                                        <div class="col-sm-8">
                                            <input id="years" name="years" class="form-control" type="text" aria-required="true" aria-invalid="true" class="error">
                                        </div>
                                    </div>
                                    
                                    
                                    <div class="form-group">
                                        <div class="col-sm-8 col-sm-offset-3">
                                            <button class="btn btn-primary" id="submitbutton" onclick="checkFyFhSubmit()" type="button">提交</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
         

        </div>
    </div>
     <%@include file="/pages/head/foot.jsp" %>
    
      <!-- simditor -->

    <script>
       /*  $(document).ready(function () { */
          /*  $("#submitbutton").click(function() {
    			if(validateForm()){
    				checkFyFhSubmit2();
    			}
            	 var url="${pageContext.request.contextPath}/classrequire/addClassrequire.do";
            	var param=$("#classrequire").serialize();
            	$.post(url,param,function(data){
            		if(data=="succ"){
            			alert("保存成功");
            			location.reload();
            		}else{
            			alert("保存失败,请再次保存！");
            		}

            	}); 
            	}); */
       /*  }); */ 
        
        
      /*   $(function(){
    		var flag = "${requestScope.resStr}";
    		if(flag == "succ"){
        		alert("保存成功");
        	}else if(flag == "fail"){
        		alert("保存失败：班级编号不可以重复！");
        	}
    	});
      */
        
        /** 表单验证  **/
    	function validateForm(){
    		if($("#classCode").val()==""){
    			alert("班级编号不可以为空");
    			return false;
    		}
    		if($("#className").val()==""){
    			alert("班级名称不可以为空");
    			return false;
    		}
    		if($("#years").val()==""){
    			alert("学年不可以为空");
    			return false;
    		}
    		
    		return true;
    	}
    	
    	 function checkFyFhSubmit(){
    		 validateForm();
    		$.ajax({
				type:"POST",
				url:"${pageContext.request.contextPath}/classrequire/addClassrequire",
				data:$("#classrequire").serialize(),
				async: true,
				dataType: "text", 
	  			error: function(request) {alert("添加信息失败！"+request.responseText);},
				success:function(data){
					var result=String($.trim(data));
					if(result == "succ"){
						alert("操作成功");
						window.location.href="./pages/classrequire/addClassrequire.jsp";
					}
					else{
						alert("操作失败：班级编号不能重复");
					}
					
				}
			});
		//return true;
    	} 
    	
    	/* function checkFyFhSubmit(){
    		 var url="${pageContext.request.contextPath}/classrequire/addClassrequire.do";
        	var param=$("#classrequire").serialize();
        	$.post(url,param,function(data){
        		if(data=="succ"){
        			alert("保存成功");
        			location.reload();
        		}else{
        			alert("保存失败,请再次保存！");
        		}

        	}); 
    	} */
    </script>
  </body>
</html>
